package com.usian.controller;

import com.usian.feign.ItemServiceFeign;
import com.usian.pojo.TbItemParam;
import com.usian.utils.PageResult;
import com.usian.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author lpf
 * @Date 2022/3/23 下午3:19
 * @ProjectName java134-e-commerce-project
 * @Version 1.0
 * @Description:
 */
@RestController
@RequestMapping(value = "backend/itemParam")
public class ItemParamController {

    @Autowired
    private ItemServiceFeign itemServiceFeign;

    /**
     * 实现商品规格参数接口（消费者）
     *
     * @param itemCatId
     * @return
     * @Auth lpf
     */
    @RequestMapping(value = "selectItemParamByItemCatId/{itemCatId}", method = RequestMethod.GET)
    public Result selectItemParamByItemCatId(@PathVariable Long itemCatId) {
        TbItemParam tbItemParam = itemServiceFeign.selectItemParamByItemCatId(itemCatId);
        if (tbItemParam != null) {
            return Result.ok(tbItemParam);
        }
        return Result.error("暂无商品信息！");
    }

    /**
     * 实现商品规格参数的删除操作
     * @param id
     * @return
     * @Auth fgg
     */
    @RequestMapping(value = "deleteItemParamById",method = RequestMethod.GET)
    public Result deleteItemParamById(Long id) {
        int res = itemServiceFeign.deleteItemParamById(id);
        if (res == 0) {
            return Result.error("删除失败！");
        }
        return Result.ok();
    }

    /**
     * liurui
     * 添加商品规格模板
     * @param tbItemParam
     * @return
     */
    @RequestMapping("insertItemParam")
    public  Result insertItemParam(TbItemParam tbItemParam){
        Integer insertItemParam = itemServiceFeign.insertItemParam(tbItemParam);
        if (insertItemParam == 1){
            return Result.ok();
        }
        return Result.error("添加失败");
    }

    /**
     * 规格模板查询接口
     * @param page
     * @param rows
     * @return
     * @Auth shangxingming
     */
    @RequestMapping("selectItemParamAll")
    public Result selectItemParamAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "3") Integer rows){
        PageResult pageResult = itemServiceFeign.selectItemParamAll(page,rows);
        if(pageResult.getResult() !=null && pageResult.getResult().size()>0){
            return Result.ok(pageResult);
        }
        return Result.error("查询失败！");
    }
}
